package utility.webmailclient.app.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import utility.webmailclient.app.usermanagement.delegate.UserProfileManager;
import utility.webmailclient.app.usermanagement.model.RegistrationFormObject;

public class RegistrationFormController extends SimpleFormController{
	
	private UserProfileManager userProfileManager;
	
	

	public UserProfileManager getUserProfileManager() {
		return userProfileManager;
	}

	public void setUserProfileManager(UserProfileManager userProfileManager) {
		this.userProfileManager = userProfileManager;
	}

	
	
	

	
	@Override
	public ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		// TODO Auto-generated method stub
		System.out.println("onsubmit called()");
		RegistrationFormObject registrationFormObject = (RegistrationFormObject)command;
		this.userProfileManager.registerUser(registrationFormObject);
		
		return new ModelAndView(getSuccessView());

		
	}


	@Override
	public ModelAndView showForm(HttpServletRequest request,
			HttpServletResponse response, BindException errors, Map controlModel)
			throws Exception {
		// TODO Auto-generated method stub
		System.out.println("show form()");
		return super.showForm(request, response, errors, controlModel);
	}
	
	


	


}
